// %%%%%%%%%%%%%%%%%%%%%%% HILO_HANDLE.H %%%%%%%%%%%%%%%%%%%%%%%
// Provides a Python interface to a HANDLE structure.
// Simple storage object; meant to be manipulated in C and passed around in Python.
// Some methods are given to the hilo module to create and close these objects.
// -------------------------------------------------------------

#ifndef _HILO_HANDLE_H_
#define _HILO_HANDLE_H_

#include "globals.h"

#include <Windows.h>
#include <Python.h>
#pragma once

//
// A simple Python object containing a HANDLE structure.
//

struct hilo_HANDLE {
	PyObject_HEAD
	HANDLE hHandle;
};

//
// Wraps functionality and data for a Python HANDLE object into a static class.
// Provides some methods that may be added to the module's exported methods.
//

class hilo_HINT {
public:

	//
	// Contains the definition of the a hilo_HANDLE object type.
	// 

	static PyTypeObject type;

	//
	// Defines the hilo_HANDLE object type within the given module.
	//

	__inline static void define( PyObject * );

	//
	// Returns a pointer to a hilo_HANDLE object from the given HANDLE structure.
	//

	__inline static PyObject* fromHandle( HANDLE * );

};

__inline void hilo_HINT::define( PyObject *module ) {
	hilo_HINT::type.tp_new = PyType_GenericNew;
	if (PyType_Ready(&hilo_HINT::type) < 0)
		return;

	Py_INCREF(&hilo_HINT::type);
	PyModule_AddObject(module, "HANDLE", (PyObject*)&hilo_HINT::type);
}

__inline PyObject* hilo_HINT::fromHandle( HANDLE *hHandle ) {
	hilo_HANDLE *self;
	self = (hilo_HANDLE*)(&hilo_HINT::type)->tp_alloc(&hilo_HINT::type, 0);
	self->hHandle = *hHandle;
    return (PyObject*)self;
}

#endif